package main

import (
	"fmt"
	"time"
)

const LIM = 20

var fibs [LIM]uint64

func main() {
	//time_()
	time_mem()
}

func time_() {
	//result := 0
	start := time.Now()
	for i := 0; i <= 40; i++ {
		fibonacci(i)
		//fmt.Printf("fibonacci(%d) is: %d\n", i, result)
	}
	end := time.Now()
	delta := end.Sub(start)
	fmt.Printf("longCalculation took this amount of time: %s\n", delta)
}

func time_mem() {
	var result uint64 = 0
	start := time.Now()
	for i := 0; i < LIM; i++ {
		result = fibonnaci_mem(i)
		fmt.Printf("fibonacci(%d) is: %d\n", i, result)
	}
	end := time.Now()
	delta := end.Sub(start)
	fmt.Printf("longCalculation took this amount of time: %s\n", delta)
}

func fibonnaci_mem(n int) (res uint64) {

	if fibs[n] != 0 {
		res = fibs[n]
		return
	}

	if n <= 1 {
		res = 1
	} else {
		res = fibonnaci_mem(n-1) + fibonnaci_mem(n-2)
	}

	fibs[n] = res
	return
}

func fibonacci(n int) (res int) {
	if n <= 1 {
		res = 1
	} else {
		res = fibonacci(n-1) + fibonacci(n-2)
	}
	return
}
